package ycl.important.service.impl.hovel;

import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import ycl.important.common.constants.RedisConstant;
import ycl.important.common.models.req.base.SmsReq;
import ycl.important.common.utils.EmailUtil;
import ycl.important.service.hovel.SmsService;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * 发送短信
 *
 * @author: YCL
 * @date: 2021-06-16 13:07:29
 */
@Service("smsService")
@Slf4j
public class SmsServiceImpl implements SmsService {

	@Resource
	private StringRedisTemplate stringRedisTemplate;
	@Resource
	private EmailUtil emailUtil;


	@Override
	public void send(String mobile, String content, String productId) {

	}

	@Override
	public void registerByUsername(SmsReq dto) {
		String code = RandomUtil.randomNumbers(6);
		stringRedisTemplate.opsForValue().set(
				RedisConstant.USER_REGISTER + dto.getMobile(), code,
				5L, TimeUnit.MINUTES);
	}

	@Override
	public void testSendEmail() {
		String code = RandomUtil.randomNumbers(6);
		stringRedisTemplate.opsForValue().set("2870903036@qq.com", code,1L, TimeUnit.MINUTES);
		emailUtil.sendEmail(
				"2870903036@qq.com",
				"测试",
				code
		);
	}
}
